package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.icid.store.business.delegate.ProductDelegate;
	import com.icid.store.event.GetProductListEvent;
	import com.icid.store.event.TryDeleteProductEvent;
	import com.icid.store.vo.ProductFilterVO;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;

	public class TryDeleteProductCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:ProductDelegate;
		private var tryDeleteProductEvent:TryDeleteProductEvent;
		public function TryDeleteProductCommand()
		{
			super();
			delegate = new ProductDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			tryDeleteProductEvent = TryDeleteProductEvent(event);
			delegate.delete_(tryDeleteProductEvent.pid);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			switch(data.result.info)
			{
				case "success":
					Alert.show("Delete product success!","SUCCESS");
					CairngormEventDispatcher.getInstance().dispatchEvent(new GetProductListEvent(new ProductFilterVO()));
					break;
				case "failure":
					Alert.show("Delete product failure!","FAILURE");
					break;
				default:
					break;		
			}
		}
		
	}
}